<script>
/**
 * title
 * @return {[type]} [description]
 */
import ImgUp from '@/components/fileupImgBase'
export default{
	components:{
		ImgUp
	},
	props:{

	},
	data(){
		return {
			visible:false,
			data:{},
			loading:false,
			fileup:{
				file:{},
				filelist:[],
			},
		}
	},
	created(){},
	mounted(){},
	methods:{
		send(){
			this.$refs.forms.validate().then(async ()=>{
				console.log('验证通过');
				this.loading=true;
				let rs = await this.muajax.brandSave({
					...this.data,
				});
				this.loading=false;
				if(rs.status==200){
					this.$message.success(rs.msg);
					this.visible=false;
				}
			}).catch(err=>{
				console.log('验证不通过');
				// this.$errorFocus(err);
			})
		},
		async datainit(){
			let rs = await this.muajax.brandGet({ id : this.param.id});
			if(rs.status==200){
				this.data=rs.data;
				if(rs.data.thumb){
					this.fileup.filelist=[{
						uid: '-1',
						name: 'image',
						status: 'done',
						url:rs.data.thumb,
					}]
				}
			}
		},//初始化本页数据
		show(show,param){
			this.visible=show;
			if(show){
				this.data={sort:10,};
				this.fileup.filelist=[];
				this.param=param;
				if(!!this.param?.id)
					this.datainit();
			}
		},

	},
	computed:{},
	watch:{},
	filters:{},
}
</script>
<template>
	<a-modal
		v-model:visible="visible"
		width="800px"
		title="品牌管理"
		:maskClosable="false"
		@ok="send"
		cancelText="取消"
		okText="提交"
		:confirmLoading="loading"
	>
		<a-form
		ref="forms"
		:model="data"
		>
			<a-form-item
				label="品牌名称"
				:labelCol="{span: 4}"
				name="name"
				:rules="[{required:true,message:'请输入品牌名称'}]"
			>
				<a-input
					placeholder="请输入"
					v-model:value="data.name"
				/>
			</a-form-item>
			<a-form-item
				label="描述内容"
				:labelCol="{span: 4}"
				name="desc"
				:rules="[{required:true,message:'请输入描述内容'}]"
			>
				<a-textarea
					placeholder="请输入"
					v-model:value="data.desc"
				/>
			</a-form-item>
			<a-form-item
				label="排序"
				:labelCol="{span: 4}"
				name="sort"
				:rules="[{required:true,type:'number',message:'请输入排序'}]"
			>
				<a-input-number
					placeholder="请输入"
					v-model:value="data.sort"
					:min="0"
					:max="9999"
				/>
			</a-form-item>
			<a-form-item
				label="上传封面"
				:labelCol="{span: 4}"
				name="thumb"
				:rules="[{required:true,message:'请上传封面',trigger: 'blur'}]"
			>
				<ImgUp
					accept="image/png, image/jpeg"
					:fileup="fileup"
					:api="muajax.api.brandFileup"
					@done="head=>data.thumb=head"
					@del="data.thumb=''"
				/>
			</a-form-item>
		</a-form>
	</a-modal>
</template>
<style lang="less" scoped>

</style>